package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 1.配置类
 * 2.定义一个交换机
 * 3.定义两个队列
 * 4.绑定队列到交换机
 */
@Configuration
public class FanoutConfig {

    // 定义交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("pay.fanout");
    }
    // 定义两个队列
    @Bean
    public Queue orderQueue(){
        return new Queue("fanout.order.queue");
    }
    @Bean
    public Queue smsQueue(){
        return new Queue("fanout.sms.queue");
    }
    // 绑定交换机和队列
    // 方法的参数一定是我们前面的方法名
    @Bean
    public Binding bindingOrderToExchange(Queue orderQueue,FanoutExchange fanoutExchange){
      return BindingBuilder.bind(orderQueue).to(fanoutExchange);
    }

    @Bean
    public Binding bindingSmsToExchange(Queue smsQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(smsQueue).to(fanoutExchange);
    }

}
